{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import h2o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import h2o_cloud_extensions as hce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Go to https://internal.dedicated.h2o.ai/auth/get-platform-token\n",
    "hce.settings.connection.refresh_token = \"TOKEN_THAT_YOU_RECIEVED_AFTER_AUTHENTICATION\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "hce.settings.connection.client_id = 'hac-platform-public'\n",
    "hce.settings.connection.token_endpoint_url = 'https://auth.internal.dedicated.h2o.ai/auth/realms/hac/protocol/openid-connect/token'\n",
    "hce.settings.mlops.api_url = 'https://mlops-api.internal.dedicated.h2o.ai'\n",
    "hce.settings.mlops.project_name = 'h2o-3-test'\n",
    "hce.settings.mlops.project_description = 'Testing project for h2o3 cloud extensions'\n",
    "hce.settings.mlops.deployment_environment = 'DEV'\n",
    "hce.settings.mlops.grid_search.automatic_publishing = False\n",
    "hce.settings.mlops.grid_search.automatic_deployment = False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "h2o.init()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Train model\n",
    "from h2o.estimators import H2OGradientBoostingEstimator\n",
    "from h2o.grid.grid_search import H2OGridSearch\n",
    "prostate = h2o.import_file(\"http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv\")\n",
    "prostate[\"CAPSULE\"] = prostate[\"CAPSULE\"].asfactor()\n",
    "predictors = [\"ID\",\"AGE\",\"RACE\",\"DPROS\",\"DCAPS\",\"PSA\",\"VOL\",\"GLEASON\"]\n",
    "response = \"CAPSULE\"\n",
    "gbm_params = {'learn_rate': [i * 0.01 for i in range(1, 11)],\n",
    "                'max_depth': list(range(2, 11)),\n",
    "                'sample_rate': [i * 0.1 for i in range(5, 11)],\n",
    "                'col_sample_rate': [i * 0.1 for i in range(1, 11)]}\n",
    "\n",
    "search_criteria = {'strategy': 'RandomDiscrete', 'max_models': 5, 'seed': 2}\n",
    "\n",
    "# Train and validate a random grid of GBMs\n",
    "gbm_grid = H2OGridSearch(model=H2OGradientBoostingEstimator,\n",
    "                          hyper_params=gbm_params,\n",
    "                          search_criteria=search_criteria)\n",
    "gbm_grid.train(x=predictors, y=response, training_frame=prostate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.is_published()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.publish()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.is_published()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.is_deployed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.deploy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gbm_grid.is_deployed()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "h2o-cloud-extensions",
   "language": "python",
   "name": "h2o-cloud-extensions"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
